<section class="content-header" >
    <h1>
        会员管理
        <small>会员类型</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="{:U('/Admin/index')}"><i class="fa fa-home"></i>首页</a></li>
        <li class="active">会员类型</li>
    </ol>
</section>
<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <div class="box-title"><label >会员分类</label></div>
                    <div class="pull-right">
                        <button class="btn btn-block btn-primary btn-sm" onclick="addGroup()"><i class="fa fa-plus"></i>&nbsp;&nbsp;&nbsp;添加类型</button>
                    </div>
                </div><!-- /.box-header -->
                <div class="box-body">
                    <table id="table" class="table table-bordered table-striped" width="100%">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>排序</th>
                                <th>名称</th>
                                <th>类型</th>
                                <th>说明</th>
                                <th>详细</th>
                                <th>卡片</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <foreach name="groups" item="group">
                                <tr>
                                    <td>{$group[id]}</td>
                                    <td><input type="text" id="group{$group[id]}" value="{$group[listorder]}"
                                               style="text-align:center;height: 20px" size="2" onchange="groupOrder({$group[id]})"/></td>
                                    <td>{$group[name]}</td>
                                    <td>{$types[$group[type]]}</td>
                                    <td>{$group[note]}</td>
                                    <td>
                                        <if condition="$group[type] eq 0">
                                            充值{$group[price]},可洗衣{$group[laundry_count]}件,赠送{$group[shopping]}元至途品汇购物
                                            <elseif  condition="$group[type] eq 1"/>
                                            充值{$group[price]}元,赠送{$group[give_price]}元，获得奢侈品护理等可消费金额{$group[luxury]}元,再赠送{$group[shopping]}元至途品汇购物
                                              <elseif  condition="$group[type] eq 2"/>
                                            充值{$group[price]}元,可洗衣{$group[laundry_count]}件，获得奢侈品护理等可消费金额{$group[luxury]}元,再赠送{$group[shopping]}元至途品汇购物
                                         </if>
                                    </td>
                                    <td><img src="{$group[thumb]}" height="45"/></td>
                                    <td>
                                        <a href="javascript:uptateGroupItem('{$group[id]}')"><i class="fa fa-edit"></i>&nbsp;编辑</a>
                                        &nbsp;&nbsp;&nbsp;<a href="javascript:deleteGroupItem('{$group[id]}')"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                                    </td>
                                </tr>
                            </foreach>
                        </tbody>
                    </table>
                </div><!-- /.box-body -->
            </div><!-- /.box -->
        </div><!-- /.col -->
    </div><!-- /.row -->
</section><!-- /.content -->
<!-- DATA TABES SCRIPT -->
<!-- page script -->
<script type="text/javascript">
    $(function () {
        $('#table').dataTable({
            "autoWidth": true,
            "processing": false, //载入数据的时候是否显示“载入中”
             ordering: false, //排序操作在服务端进行，所以可以关了。
            "paging": false,
            "searching": false,
            "language": lang
        });
    });
    //排序
    function groupOrder(id){
        $.post('{:U("member/order_group")}', "order="+$('#group'+id).val()+"&id="+id, function(res){
            if(!res.status){
                $.messager.alert('提示信息', res.info, 'error');
            }else{
               reloadContent();
            }
        }, 'json');
    }

    function uptateGroupItem(id) {
        $.dialog("{:U('member/addGroup')}", '添加会员类型', "id=" + id,42);
    }

    function deleteGroupItem(id) {
        $.messager.confirm('确认删除', '确认要删除会员类型？', function () {
            $.ajax({
                url: "{:U('member/deleteGroup')}",
                data: "id=" + id,
                success: function (json) {
                    if (!json.status) {
                        dialog({
                            "title": '提示信息',
                            "width": '20em',
                            'content': json.info
                        }).show();
                    } else {
                        dialog({
                            "title": '提示信息',
                            "width": '20em',
                            'content': json.info
                        }).show();
                    }
                    reloadContent();
                }
            });
        });
    }

    function addGroup() {
        $.dialog("{:U('member/addGroup')}", '添加会员类型',null,42);
    }
</script>